<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script>
{% if isLogin %}
	//获取到授权并登录后，原登录页跳转到首页，其它页面则刷新
	var targetWin = window.opener.parent ? window.opener.parent : window.opener;
	var getQuery = function(name){
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = targetWin.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]); return null;
	}

	if(getQuery('next')){
		targetWin.location.href = getQuery('next');
	}else{
		if(targetWin.location.href.indexOf('/u/join') > -1 || targetWin.location.href.indexOf('/u/sign') > -1 ){
			targetWin.location.href = '/u/subscribe/all/';
		}else{
			targetWin.location.reload();
		}
	}
	window.close();
{% endif %}

{% if user_data %}
	{% if account_type == 'qq' %}
    var user_data = {
            'token': '{{token}}',
            'expires': {{expires}},
            'account_type': 2,
            'app_uid': '{{qzone_user_data.app_uid}}',
            'username': '{{qzone_user_data.nickname}}',
            'gender':  {%if qzone_user_data.gender =='男'%}'m'{%else%}'f'{%endif%},
            'avatar': '{{qzone_user_data.figureurl_qq_1}}',
            'email': ''
        };
	{% endif %}
	
	{% if account_type == 'sina' %}
	var user_data = {
			'token': '{{token}}',
			'expires': {{expires}},
			'account_type': 1,
			'app_uid': '{{user_data.id}}',
			'username': '{{user_data.screen_name}}',
			'gender':  {%if user_data.gender=='f'%}'f'{%else%}'m'{%endif%},
			'avatar': '{{user_data.avatar_large}}',
			'email': '{{user_email}}'
		};
	{% endif %}

	{% if is_mobile %}
		/*
		 * mobile site与website存在跨子域的问题,不能直接写localstorage
		 * 所以这里添加iframe,通过postmessage让mobilesite自己写本地存储.
		 * 完成后再跳转到注册页面,目前来说这是改动量最小的方案.
		 */
		localStorage.setItem('mt-user-data', JSON.stringify(user_data))
		window.location.href = '/u/sign/';
	{% else %}
		if(window.opener.mtAuth){
			window.opener.mtAuth.fillAccount(user_data);
			window.close();
		}else{
			window.opener.location.href = '/u/join/';
			setTimeout(function(){
		        window.opener.mtAuth.fillAccount(user_data);
		        window.close();
		    }, 1500);
		}
	{% endif %}
{% endif %}
</script>
</body>
</html>